package ifgi.potwc.ipt.store;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.annotation.SuppressLint;

/**
 * This class is a storage for general attributes and methods.
 * 
 * @author saschak.
 */
public class Store
{
    // Multipliers for sensor reading and upload frequencies
    public static final int SECONDS = 1000;
    public static final int MINUTES = 60 * SECONDS;
    public static final int HOURS = 60 * MINUTES;

    // Keys for SharedPreferences
    public static final String FEED_ID = "feedID";
    public static final String LAST_FEED_ID ="lastFeedID";
    public static final String TRACKING_STATUS = "trackingStatus";

    // ***************************************************************************
    // General methods

    /**
     * Round a double value to a certain number of decimals.
     * 
     * @param _unrounded
     *            The double value to be rounded
     * @param _decimals
     *            The number of decimals after the point
     * @return The rounded double value
     */
    public static double round(double _unrounded, int _decimals)
    {
	int factor = (int) Math.pow(10, _decimals);

	return (double) Math.round(_unrounded * factor) / factor;
    }

    /**
     * Returns the current time as timestamp, i.e. 2012-11-23T13:41:15Z.
     * 
     * @return The current timestamp
     */
    @SuppressLint("SimpleDateFormat")
    public static String getTimestamp()
    {
	// Calendar instance
	Calendar cal = Calendar.getInstance();

	// Timestamp format for Cosm, i.e. "2012-11-28T10:42:08Z"
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

	// Current timestamp
	String timestamp = sdf.format(cal.getTime());

	return timestamp;
    }
}
